<?php
  include_once('conn.php');
  
  // 接收由登录页面传来的数据
  $username = $_POST['username'];
  $password = $_POST['password'];
  if(strlen($username) < 5) {
    alert('用户名不能小于5位', 'login.php');
    exit();
  }

  $sql = "select * from user where username = '$username' and password = '$password'";
  $result = mysqli_query($conn, $sql);
  if(mysqli_num_rows($result) > 0) {
    $_SESSION['username'] = $username;
    alert('登陆成功', 'admin');
  } else {
    alert('用户名或密码错误', 'login.php');
  }

  mysqli_close($conn);
?>